package com.projectx.action.contact;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.projectx.R;

public class FindFriendAdapter extends RecyclerView.Adapter<FindFriendAdapter.VH> {

    private Context context;
    private String text;
    public FindFriendAdapter(Context context, String text) {
        this.context = context;
        this.text=text;
    }

    @NonNull
    @Override
    public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item, parent, false);
        return new VH(view);
    }

    @Override
    public void onBindViewHolder(@NonNull VH holder, final int position) {
        if (position==0){
            holder.textView.setText("找人: "+ FindFriend.text);
            holder.imageView.setImageResource(R.drawable.ic_perm_identity_black_24dp);
        }
        if (position==1){
            holder.textView.setText("找群: "+ FindFriend.text);
            holder.imageView.setImageResource(R.drawable.ic_group_black_24dp);
        }
        holder.click.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                // 点击事件
                Intent intent=new Intent(context,FindPerson.class);
                intent.putExtra("text",text);
                intent.putExtra("position",position);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                arg0.getContext().startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return 2;
    }

    public static class VH extends RecyclerView.ViewHolder {

        TextView textView;
        ImageView imageView;
        View click;
        public VH(@NonNull View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.text);
            imageView= itemView.findViewById(R.id.imageView);
            click=itemView.findViewById(R.id.click);
        }
    }
}
